package com.hxkcloud.patient.activitys;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.YjhApplication;
import com.hxkcloud.patient.beans.FileUploadBean;
import com.hxkcloud.patient.beans.LoginInfo;
import com.hxkcloud.patient.beans.PatientCaseNumberBean;
import com.hxkcloud.patient.beans.UpdateUserInfo;
import com.hxkcloud.patient.beans.resultbeans.ObjectResultBean;
import com.hxkcloud.patient.config.ApplicationConfig;
import com.hxkcloud.patient.dborm.LoginInfoDao;
import com.hxkcloud.patient.popup.AreaSelectPop;
import com.hxkcloud.patient.popup.DateSelectorPopWindow;
import com.hxkcloud.patient.popup.PictureSelectPopupWindow;
import com.hxkcloud.patient.request.MessageCode;
import com.hxkcloud.patient.request.YiJiaHuNetWorkUtils;
import com.hxkcloud.patient.utils.BrightnessUtils;
import com.hxkcloud.patient.utils.ImageOptionUtils;
import com.hxkcloud.patient.utils.ImageVideoUtils;
import com.hxkcloud.patient.utils.StringUtil;
import com.hxkcloud.patient.utils.UriUtils;
import com.hxkcloud.patient.views.CircleImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Created by ray_lei on 2016/7/10.
 */
public class PersonalInfoForPatientActivity extends BaseActivity implements View.OnClickListener, PictureSelectPopupWindow.FinishListener, AreaSelectPop.onAreaSelectListener {

    private LinearLayout ll_title;
    private ImageView iv_back;
    private TextView tv_title;
    private TextView tv_finish;

    private CircleImageView iconView;
    private Button choosepicBtn;
    private EditText nameET;
    private EditText sexET;
    private EditText birthET;
    private EditText heightET;
    private EditText weightET;
    private EditText bmiET;
    //    private EditText addressET;
    private TextView addressTV;
    private EditText et_number;//病案号

    private PopupWindow popup_sex;//选择性别的popup
    private Button bt_male;
    private Button bt_female;
    private Button bt_cancel;

    private PictureSelectPopupWindow picSelect;

    private static final int TAKE_PHOTO_PICTURE = 1;
    private static final int TAKE_PHOTO_VIDEO = 2;
    private static final int SELECT_PICTURE = 3;
    private static final int SELECT_VIDEO = 4;
    private static final int CUT_PICTURE = 5;

    private DateSelectorPopWindow dateSelect;
    private AreaSelectPop areaSelectPop;

    private LoginInfo userInfo;

    private ObjectResultBean<UpdateUserInfo> resultBean;

    private List<FileUploadBean> fileResultBean;

    private Bitmap mBitmap = null;
    private String userIconPath = "";
    private String userIconUrl = "";

    private String province = "";
    private String city = "";
    private String area = "";
    private String areaId = "";

    LoginInfoDao userDao;
    private String imgUrl = "";
    @Override
    protected void updateByHandler(Message msg) {

        switch (msg.what) {
            case MessageCode.NETWORKCODE_UPDATEUSERINFO_SUCCESS:
                dismisssLoading();
                Log.i("----msgUrlobj---->",msg.obj.toString());
                if (msg.obj != null) {
                    resultBean = (ObjectResultBean<UpdateUserInfo>) msg.obj;
                    imgUrl = resultBean.getData().getImage();
                    if (imgUrl!=null){
                        Log.i("----msgUrl---->","imgUrl:"+imgUrl.toString());
                    }
                    //loginInfo.setHeadImg(imgUrl);
                    toastMsg(resultBean.getMessage());
                    if (!TextUtils.isEmpty(areaId)) {
                        userInfo.setAddress(province + city + area);
                        userInfo.setAddressId(areaId);
                    } else {
                        userInfo.setAddress(loginInfo.getAddress());
                        userInfo.setAddressId(loginInfo.getAddressId());
                    }
                    Log.i("----userIconUrl---->",userIconUrl.toString());
                    if (!TextUtils.isEmpty(userIconUrl)) {
                        userInfo.setHeadImg(userIconUrl);
                    } else {
                        userInfo.setHeadImg(loginInfo.getHeadImg());
                    }
                    userDao.setUser(userInfo);
                    finish();
                }

                break;
            case MessageCode.NETWORKCODE_UPDATEUSERINFO_FAILURE:
                dismisssLoading();
                Log.i("----msg---->","msgfail:"+msg.obj);
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;
            case MessageCode.NETWORKCODE_FILEUPLOAD_SUCCESS:
                if (msg.obj != null) {
                    fileResultBean = (List<FileUploadBean>) msg.obj;
                    userIconPath = fileResultBean.get(0).getFilePath();
                    userIconUrl = fileResultBean.get(0).getUrl();
                    iconView.setImageBitmap(mBitmap);
                }
                break;
            case MessageCode.NETWORKCODE_FILEUPLOAD_FAILURE:
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                } else {
                    toastMsg(getResources().getString(R.string.fileuploadfail));
                }
                break;
            case MessageCode.NETWORKCODE_PATIENTCASENUMBER_SUCCESS:
                PatientCaseNumberBean caseNumberBean = (PatientCaseNumberBean) msg.obj;
                if (caseNumberBean != null) {
                    String caseNumber = caseNumberBean.getCaseNumber();
                    loginInfo.setCaseNumber(caseNumber);
                    userDao.setUser(loginInfo);
                }
                et_number.setText(loginInfo.getCaseNumber());
                break;
            case MessageCode.NETWORKCODE_PATIENTCASENUMBER_FAILURE:
                et_number.setText(loginInfo.getCaseNumber());
                break;
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_personalinfoforpatient);
        userDao = new LoginInfoDao(mContext);
        userInfo = userDao.getUser();
        initView();
        initData();
        initListener();
        areaSelectPop = new AreaSelectPop(PersonalInfoForPatientActivity.this, this);
        YiJiaHuNetWorkUtils.patientCaseNumber(handler);
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
        iv_back = (ImageView) findViewById(R.id.iv_title_back);
        tv_title = (TextView) findViewById(R.id.tv_title_title);
        tv_finish = (TextView) findViewById(R.id.tv_title_func);

        setTitlePadding(ll_title);
        iv_back.setVisibility(View.VISIBLE);
        tv_title.setText(getResources().getText(R.string.persoanlinfo_text_title));
        tv_finish.setVisibility(View.VISIBLE);
        tv_finish.setText(getResources().getText(R.string.persoanlinfo_text_finish));
        iv_back.setOnClickListener(this);
        tv_finish.setOnClickListener(this);

        nameET = (EditText) findViewById(R.id.personalinfoforpatient_et_name);
        sexET = (EditText) findViewById(R.id.personalinfoforpatient_et_sex);
        birthET = (EditText) findViewById(R.id.personalinfoforpatient_et_birth);
        heightET = (EditText) findViewById(R.id.personalinfoforpatient_et_height);
        weightET = (EditText) findViewById(R.id.personalinfoforpatient_et_weight);
        bmiET = (EditText) findViewById(R.id.personalinfoforpatient_et_bmi);
//        addressET = (EditText) findViewById(R.id.personalinfoforpatient_et_address);
        addressTV = (TextView) findViewById(R.id.personalinfoforpatient_tv_address);
        et_number = (EditText) findViewById(R.id.personalinfoforpatient_et_number);

        iconView = (CircleImageView) findViewById(R.id.personalinfoforpatient_ci_logo);
        choosepicBtn = (Button) findViewById(R.id.personalinfoforpatient_btn_choosepic);

        LinearLayout.LayoutParams lp_icon = new LinearLayout.LayoutParams(screenWidth / 4, screenWidth / 4);
        lp_icon.gravity = Gravity.CENTER_HORIZONTAL;
        iconView.setLayoutParams(lp_icon);

        heightET.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (StringUtil.isEmpty(s.toString())) {

                } else {
                    double weight = 0;
                    if ("".equals(weightET.getText().toString().trim()) && !".".equals(heightET.getText().toString().trim())) {
                        weight = 0;
                    } else {
                        weight = Double.parseDouble(weightET.getText().toString());
                    }
                    double height = 0;
                    String bmi = "";
                    if ("".equals(s.toString()) || ".".equals(s.toString())) {
                        height = 0;
                    } else {
                        height = Double.parseDouble(s.toString()) / 100;
//                        bmi = new java.text.DecimalFormat("#.00").format(weight / (height * height));
                        if (weight == 0 || height == 0) {
                            bmiET.setText("");
                        } else {
                            if (height == 0) {
                                bmiET.setText("");
                            } else {
                                bmi = new java.text.DecimalFormat("#.00").format(weight / (height * height));
                                bmiET.setText(bmi);
                            }
                        }
                    }
                    bmiET.setText(bmi);
                    if ("".equals(s.toString()) || ".".equals(s.toString())) {

                    } else {
                        if (Double.parseDouble(s.toString()) > 0 && Double.parseDouble(s.toString()) < 300) {

                        } else {
                            toastMsg(getResources().getString(R.string.userinfo_text_inputrightheight));
                            return;
                        }
                    }


                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        weightET.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (StringUtil.isEmpty(s.toString())) {

                } else {
                    double weight = 0;

                    if ("".equals(s.toString()) || ".".equals(s.toString())) {
                        weight = 0;
                    } else {
                        weight = Double.parseDouble(s.toString());
                    }
                    double height = 0;
                    String bmi = "";
                    if (!"".equals(heightET.getText().toString().trim()) && !".".equals(heightET.getText().toString().trim())) {
                        height = Double.parseDouble(heightET.getText().toString()) / 100;
//                        bmi = new java.text.DecimalFormat("#.00").format(weight / (height * height));
                        if (weight == 0 || height == 0) {
                            bmiET.setText("");
                        } else {
                            if (height == 0) {
                                bmiET.setText("");
                            } else {
                                bmi = new java.text.DecimalFormat("#.00").format(weight / (height * height));
                                bmiET.setText(bmi);
                            }
                        }
                    }
                    bmiET.setText(bmi);
                    if (weight > 0 && weight < 300) {

                    } else {
                        toastMsg(getResources().getString(R.string.userinfo_text_inputrightweight));
                        return;
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        picSelect = new PictureSelectPopupWindow(this, screenWidth,
                screenHeight, this);

        initPopup();
    }

    @Override
    protected void initListener() {
        iv_back.setOnClickListener(this);
        sexET.setOnClickListener(this);
//        birthET.setOnClickListener(this);
//        addressET.setOnClickListener(this);
        addressTV.setOnClickListener(this);
        choosepicBtn.setOnClickListener(this);
        tv_finish.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        DisplayImageOptions option = null;
        boolean isYoung = true;
        if (!TextUtils.isEmpty(loginInfo.getAge())) {
            int ageYear = Integer.valueOf(loginInfo.getAge().split("-")[0]);
            Calendar calendar = Calendar.getInstance();
            int curYear = calendar.get(Calendar.YEAR);
            if (curYear - ageYear > 49) {
                isYoung = false;
            } else {
                isYoung = true;
            }
        }
        if (loginInfo.getSex().equals("0")) {//male
            if (!isYoung) {
                option = ImageOptionUtils.getInstance().getMan50HeadOptions();
            } else {
                option = ImageOptionUtils.getInstance().getMan20HeadOptions();
            }
        } else {//female
            if (!isYoung) {
                option = ImageOptionUtils.getInstance().getWoman50HeadOptions();
            } else {
                option = ImageOptionUtils.getInstance().getWoman20HeadOptions();
            }
        }
        imageLoader.displayImage(loginInfo.getHeadImg(), iconView, option);

        nameET.setText(loginInfo.getName());
        if ("0".equals(loginInfo.getSex())) {
            sexET.setText(getResources().getString(R.string.male));
        } else if ("1".equals(loginInfo.getSex())) {
            sexET.setText(getResources().getString(R.string.female));
        }

        if (!TextUtils.isEmpty(loginInfo.getAge())) {
            int age = Integer.valueOf(loginInfo.getAge().split("-")[0]);
            int birthYear = Calendar.getInstance().get(Calendar.YEAR) - age;
            birthET.setText(birthYear + "");
        }
        if (loginInfo.getHeight().equals("0")) {
        } else if (loginInfo.getHeight().equals("0.00")) {
        } else {
            heightET.setText(loginInfo.getHeight());
        }
        if (loginInfo.getWeight().equals("0")) {
        } else if (loginInfo.getWeight().equals("0.00")) {
        } else {
            weightET.setText(loginInfo.getWeight());
        }
//        体质指数（BMI）=体重（kg）÷身高^2（m）
//        EX：70kg÷（1.75×1.75）=22.86
        double weight = Double.parseDouble(loginInfo.getWeight());
        double height = Double.parseDouble(loginInfo.getHeight()) / 100;
        if (weight == 0 || height == 0) {
            bmiET.setText("");
        } else {
            if (height == 0) {
                bmiET.setText("");
            } else {
                String bmi = new java.text.DecimalFormat("#.00").format(weight / (height * height));
                bmiET.setText(bmi);
            }
        }
//        addressET.setText(loginInfo.getAddress());
        addressTV.setText(loginInfo.getAddress());
        et_number.setText(loginInfo.getCaseNumber());
    }

    private void initPopup() {
        popup_sex = new PopupWindow(this);
        View viewSex = LayoutInflater.from(this).inflate(R.layout.popup_selectsex, null);
        popup_sex.setContentView(viewSex);

        popup_sex.setWidth(screenWidth);
        popup_sex.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        popup_sex.setFocusable(true);
        popup_sex.setTouchable(true);
        popup_sex.setOutsideTouchable(true);
        popup_sex.setBackgroundDrawable(new ColorDrawable(0x00000000));
        popup_sex.setAnimationStyle(R.style.popupwindow_anim_default);

        bt_male = (Button) viewSex.findViewById(R.id.bt_selectsex_male);
        bt_female = (Button) viewSex.findViewById(R.id.bt_selectsex_female);
        bt_cancel = (Button) viewSex.findViewById(R.id.bt_selectsex_cancel);

        bt_male.setOnClickListener(this);
        bt_female.setOnClickListener(this);
        bt_cancel.setOnClickListener(this);

        popup_sex.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                BrightnessUtils.lightOn(PersonalInfoForPatientActivity.this);
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_back://back
                finish();
                break;
            case R.id.personalinfoforpatient_et_sex:
                closeInputMethodManager();
                popup_sex.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                BrightnessUtils.lightOff(PersonalInfoForPatientActivity.this);
                break;
            case R.id.bt_selectsex_male:
                sexET.setText(getResources().getText(R.string.male));
                popup_sex.dismiss();
                break;
            case R.id.bt_selectsex_female:
                sexET.setText(getResources().getText(R.string.female));
                popup_sex.dismiss();
                break;
            case R.id.bt_selectsex_cancel:
                popup_sex.dismiss();
                break;
            case R.id.personalinfoforpatient_et_birth:
//                if (dateSelect == null) {
//                    dateSelect = new DateSelectorPopWindow(this);
//                    dateSelect.setTimeListener(new DateSelectorPopWindow.TimeListener() {
//                        @Override
//                        public void setTime(String time) {
//                            String birthDay = time.replace(".", "-");
//                            birthET.setText(birthDay);
//
//
//                        }
//                    });
//                }
//                dateSelect.show(ll_title);
                break;
//            case R.id.personalinfoforpatient_et_address:
//                Intent iAddress = new Intent(mContext, UserAddressActivity.class);
//                if (!TextUtils.isEmpty(areaId)) {
//                    iAddress.putExtra("provincename", province);
//                    iAddress.putExtra("cityname", city);
//                    iAddress.putExtra("areaname", area);
//                }
//                startActivityForResult(iAddress, 1);
//                break;
            case R.id.personalinfoforpatient_tv_address:
//                Intent iAddress = new Intent(mContext, UserAddressActivity.class);
//                if (!TextUtils.isEmpty(areaId)) {
//                    iAddress.putExtra("provincename", province);
//                    iAddress.putExtra("cityname", city);
//                    iAddress.putExtra("areaname", area);
//                }
//                startActivityForResult(iAddress, 1);
                closeInputMethodManager();
                areaSelectPop.show(ll_title);
                break;
            case R.id.personalinfoforpatient_btn_choosepic:
                picSelect.setType(1);
                picSelect.showAtLocation(ll_title, Gravity.BOTTOM, 0, 0);
                break;
            case R.id.tv_title_func:
                String name = nameET.getText().toString();
                String sex = sexET.getText().toString();
                String birth = birthET.getText().toString();
                String height = heightET.getText().toString();
                String weight = weightET.getText().toString();
                String caseNumber = et_number.getText().toString();

                if (TextUtils.isEmpty(name) || TextUtils.isEmpty(birth) || TextUtils.isEmpty(caseNumber)) {
                    toastMsg(R.string.pleaseinputimportantitems);
                    return;
                }

                if (getResources().getString(R.string.male).equals(sex)) {
                    userInfo.setSex("0");
                } else if (getResources().getString(R.string.female).equals(sex)) {
                    userInfo.setSex("1");
                }
                if (!TextUtils.isEmpty(name)) {
                    userInfo.setName(name);
                } else {
                    userInfo.setName("");
                }
                userInfo.setUserId(loginInfo.getUserId());
                userInfo.setUserStyle(loginInfo.getUserStyle());
                if (!TextUtils.isEmpty(userIconPath)) {
                    userInfo.setHeadImg(userIconPath);
                }
                if (!TextUtils.isEmpty(areaId)) {
                    userInfo.setAddress(areaId);
                } else {
                    userInfo.setAddress(loginInfo.getAddressId());
                }

                int age = Integer.valueOf(birth);
                int birthYear = Calendar.getInstance().get(Calendar.YEAR) - age;
                String birthDay = birthYear + "-01-01";
                userInfo.setAge(birthDay);
                if (!TextUtils.isEmpty(height)) {
                    userInfo.setHeight(height);
                    if (!(Double.parseDouble(height) > 0 && Double.parseDouble(height) < 300)) {
                        toastMsg(getResources().getString(R.string.userinfo_text_inputrightheight));
                        return;
                    }


                } else {
                    userInfo.setHeight("0.00");
//                    toastMsg(getResources().getString(R.string.userinfo_text_inputheight));
                }
                if (!TextUtils.isEmpty(weight)) {
                    userInfo.setWeight(weight);
                    if (!(Double.parseDouble(weight) > 0 && Double.parseDouble(weight) < 300)) {
                        toastMsg(getResources().getString(R.string.userinfo_text_inputrightweight));
                        return;
                    }
                } else {
                    userInfo.setWeight("0.00");
//                    toastMsg(getResources().getString(R.string.userinfo_text_inputweight));
                }
                userInfo.setCaseNumber(caseNumber);
                loading();
                YiJiaHuNetWorkUtils.updateUserInfo(userInfo, handler);
                break;
        }
    }

    // 上传文件的内容

    private File cameraPath;
    private File cameraFile;
    private String cameraFileName;

    @Override
    public void onFinished(int options, int type) {
        cameraPath = new File(ApplicationConfig.PicAndVideoUrl);
        if (!cameraPath.exists()) {
            cameraPath.mkdirs();
        }
        Intent mIntent;
        if (options == 1) {// 打开相机
            if (type == 1) {// 拍照
                mIntent = new Intent();
                mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                if (cameraFileName == null) cameraFileName = System.currentTimeMillis() + ".jpg";
                if (cameraFile == null) cameraFile = new File(cameraPath, cameraFileName);
                mIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                        Uri.fromFile(cameraFile));
                startActivityForResult(mIntent,
                        TAKE_PHOTO_PICTURE);
            }
        } else if (options == 2) {// 打开相册
            if (type == 1) {// 相册选择照片
                mIntent = new Intent(
                        Intent.ACTION_PICK,
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                mIntent.setDataAndType(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
                startActivityForResult(mIntent,
                        SELECT_PICTURE);
            }
        }

    }

    private Uri imageUri = null;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case TAKE_PHOTO_PICTURE:// 照相
                    if (resultCode == Activity.RESULT_OK) {
                        if (cameraFile != null) {
                            File outFile = new File(cameraPath, cameraFileName);
                            ImageVideoUtils.compressPicture(cameraFile, outFile);
                            imageUri = Uri.fromFile(outFile);

                            if (imageUri != null) {
                                   // ImageVideoUtils.compressPicture(cameraFile, cameraFile);
                                    mBitmap = BitmapFactory.decodeFile(outFile.getAbsolutePath());
                                    List<File> images = new ArrayList<>();
                                    images.add(cameraFile);
                                    YiJiaHuNetWorkUtils.FileUpload(images, YjhApplication.file_image, handler);
                            }
                            imageUri = null;

//                            Intent intent = new Intent("com.android.camera.action.CROP");
//                            intent.setDataAndType(Uri.fromFile(outFile), "image/*");
//                            // 下面这个crop=true是设置在开启的Intent中设置显示的VIEW可裁剪
//                            intent.putExtra("crop", "true");
//                            // aspectX aspectY 是宽高的比例
//                            intent.putExtra("aspectX", 1);
//                            intent.putExtra("aspectY", 1);
//                            // outputX outputY 是裁剪图片宽高
//                            //				intent.putExtra("outputX", 150);
//                            //				intent.putExtra("outputY", 150);
//                            intent.putExtra("return-data", false);
//                            intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//文件输出路径
//                            intent.putExtra("outputFormat", "JPEG"); //输入文件格式
//                            startActivityForResult(intent, CUT_PICTURE);
                        }
                    }
                    break;
                case SELECT_PICTURE:// 选择照片
                    if (resultCode == Activity.RESULT_OK) {
                        if (data.getData() != null) {
                            Uri uri = data.getData();
                            if (uri != null) {
                                //创建图片保存目录

//                                cameraFileName = System.currentTimeMillis() + ".jpg";
//                                cameraFile = new File(cameraPath, cameraFileName);
//                                imageUri = Uri.fromFile(cameraFile);

                                String u = UriUtils.getPath(mContext,uri);
                                cameraFile = new File(u);
                                ImageVideoUtils.compressPicture(cameraFile, cameraFile);

                                mBitmap = BitmapFactory.decodeFile(cameraFile.getAbsolutePath());

                                List<File> images = new ArrayList<>();
                                images.add(cameraFile);
                                YiJiaHuNetWorkUtils.FileUpload(images, YjhApplication.file_image, handler);



//                                Intent intent = new Intent("com.android.camera.action.CROP");
//                                intent.setDataAndType(uri, "image/*");
//                                // 下面这个crop=true是设置在开启的Intent中设置显示的VIEW可裁剪
//                                intent.putExtra("crop", "true");
//                                // aspectX aspectY 是宽高的比例
//                                intent.putExtra("aspectX", 1);
//                                intent.putExtra("aspectY", 1);
//                                // outputX outputY 是裁剪图片宽高
////							intent.putExtra("outputX", 150);
////							intent.putExtra("outputY", 150);
//                                intent.putExtra("return-data", false);
//                                intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);//文件输出路径
//                                intent.putExtra("outputFormat", "JPEG"); //输入文件格式
//                                startActivityForResult(intent, CUT_PICTURE);

                            }
                        }
                    }
                    break;
                case CUT_PICTURE://图片裁剪
                    if (imageUri != null) {
                        if (cameraFile != null) {
                            ImageVideoUtils.compressPicture(cameraFile, cameraFile);
                            mBitmap = BitmapFactory.decodeFile(cameraFile.getAbsolutePath());
                            List<File> images = new ArrayList<>();
                            images.add(cameraFile);
                            YiJiaHuNetWorkUtils.FileUpload(images, YjhApplication.file_image, handler);
                        }
                    }
                    imageUri = null;
                    break;
            }
        }
        if (resultCode == 1) {
            if (data.getExtras() != null) {
                province = data.getStringExtra("province");
                city = data.getStringExtra("city");
                area = data.getStringExtra("area");
                areaId = data.getStringExtra("areaId");
//                addressET.setText(province + city + area);
                addressTV.setText(province + city + area);
            }
        }
    }


    @Override
    public void onSelect(String p, String c, String a, String id) {
        province = p;
        city = c;
        area = a;
        areaId = id;
        addressTV.setText(province + city + area);

    }
}
